package hlhj.fhp.supreme.customview

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.ReadDetailBean
import kotlinx.android.synthetic.main.classes_pop.view.*
import java.util.ArrayList

/**
 * Created by Administrator on 2018\3\21 0021.
 */
class ClassesPop(private val context: Context,private val datas:ArrayList<ReadDetailBean.DataBean.LessonBean>?,private val listener:OnClassClickListener) :PopupWindow() {
    private lateinit var adp:BaseQuickAdapter<ReadDetailBean.DataBean.LessonBean,BaseViewHolder>
    init {
        setPop()
    }

    fun setPop(){
        this.animationStyle=R.style.class_pop_style
        this.width=LinearLayout.LayoutParams.MATCH_PARENT
        this.height=LinearLayout.LayoutParams.WRAP_CONTENT
        contentView=LayoutInflater.from(context).inflate(R.layout.classes_pop,null)
        adp=object :BaseQuickAdapter<ReadDetailBean.DataBean.LessonBean,BaseViewHolder>(R.layout.classes_pop_item,datas){
            override fun convert(helper: BaseViewHolder?, item: ReadDetailBean.DataBean.LessonBean?) {
                    helper?.setText(R.id.itemTv,"第${item?.sort}课")
            }
        }

        contentView.recyclerview.adapter=adp
        contentView.recyclerview.layoutManager=LinearLayoutManager(context,LinearLayout.VERTICAL,false)

        adp.setOnItemClickListener { adapter, view, position ->
            listener.onClickClass(position)
        }

    }
    interface OnClassClickListener{
        fun onClickClass(i:Int)
    }
}